package com.leapp.sk.viewdelegate.adapter.notify

import android.content.Context
import android.content.Intent
import android.support.v4.content.ContextCompat
import android.view.View
import android.widget.TextView
import com.example.mvp.delegate.BaseAdapterDelegate
import com.example.util.finallist.CLASS_NOTIFY_DATA
import com.leapp.sk.R
import com.leapp.sk.bean.ClassNotifyEntiry
import com.leapp.sk.bean.ParentClassNotifyEntity
import com.leapp.sk.ui.activity.notify.ClasaNotifyDetialActivity

/**
 * 班级通知适配器视图托管类
 * @author  chaohaipeng  on 2018/8/2.
 */
class ClassNotifyParentAdapterDelegate : BaseAdapterDelegate() {
    override fun getOptionsMenuId(): Int {
        return 0
    }

    override fun initWidget() {
    }

    override fun onDestroy() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.adapter_class_notify
    }

    /**
     * 初始化数据
     */
    fun initData(context: Context, data: ParentClassNotifyEntity) {
        val tv_acn_notify_date = getView<TextView>(R.id.tv_acn_notify_date)
        val tv_acn_notify_title = getView<TextView>(R.id.tv_acn_notify_title)
        val tv_acn_notify_stutate = getView<TextView>(R.id.tv_acn_notify_stutate)
        val tv_acn_notify_content = getView<TextView>(R.id.tv_acn_notify_content)
        tv_acn_notify_date?.text = data?.createDate
        tv_acn_notify_title?.text = data?.title
        tv_acn_notify_content?.text = data?.content
        if (data.readStatus==1){
            tv_acn_notify_stutate?.text=context.resources.getString(R.string.string_im_unread)
            tv_acn_notify_stutate?.setTextColor(ContextCompat.getColor(context,R.color.color_FF4447))
        }else{
            tv_acn_notify_stutate?.text=context.resources.getString(R.string.string_im_read)
            tv_acn_notify_stutate?.setTextColor(ContextCompat.getColor(context,R.color.color_A3A5A8))
        }

        initEvent(context,data)

    }

    /**
     * 初始化事件
     */
    private fun initEvent(context: Context, data: ParentClassNotifyEntity) {
        val tv_acn_check_detial = getView<TextView>(R.id.tv_acn_check_detial)
        tv_acn_check_detial.setOnClickListener(View.OnClickListener {
            val intent = Intent(context, ClasaNotifyDetialActivity::class.java)
            intent.putExtra(CLASS_NOTIFY_DATA,data)
            context.startActivity(intent)
        })
    }


}